head(hh)## year district hh labor_hh income_hh expense_hh_1 expense_hh_2
## 1 101 松山區 79229 1.35 1728993 363052 1061992
## 2 101 信義區 87400 1.50 1643281 301331 982926
## 3 101 大安區 118421 1.21 1818332 340185 1113472
## 4 101 中山區 94852 1.37 1528923 287170 965483
## 5 101 中正區 63449 1.14 1611679 274992 987505
## 6 101 大同區 49201 1.47 1373177 269219 891867
head(district_house_price_df)## year quarter road_1 road_2 road_width place_type
## 1 101 三 延平北路2段 延平北路2段1號至100號 16 臨街地
## 2 101 三 承德路3段 承德路3段101號至200號 40 路角地
## 3 101 三 承德路3段 承德路3段101號至200號 40 路角地
## 4 101 三 承德路3段 承德路3段101號至200號 40 路角地
## 5 101 三 承德路3段 承德路3段101號至200號 40 臨街地
## 6 101 三 承德路3段 承德路3段208巷1號至100號 11 臨街地
## building_type structure construction_year floor_1 floor_2
## 1 住宅大樓 鋼筋混凝土造 9809 15 15
## 2 住宅大樓 鋼筋混凝土造 9608 4 12
## 3 住宅大樓 鋼筋混凝土造 9608 3 12
## 4 住宅大樓 鋼筋混凝土造 9608 6 12
## 5 公寓 鋼筋混凝土造 6111 3 4
## 6 住宅大樓 鋼筋混凝土造 9605 5 11
## location_type area_transfer house_transfer ttl_price price_per district
## 1 商業區 2.65 24.38 2120 86.96 大同區
## 2 商業區 1.17 12.63 638 50.51 大同區
## 3 商業區 1.17 12.63 620 49.09 大同區
## 4 商業區 1.98 21.88 988 45.16 大同區
## 5 商業區 12.55 37.50 1760 46.93 大同區
## 6 商業區 2.06 13.40 696 51.94 大同區
## # A tibble: 12 x 2
## district avg_income
## <chr> <dbl>
## 1 大安區 1881940
## 2 松山區 1718988
## 3 信義區 1639282
## 4 中正區 1636537
## 5 內湖區 1614290
## 6 士林區 1582343
## 7 北投區 1491120
## 8 文山區 1488390
## 9 中山區 1468947
## 10 大同區 1377881
## 11 南港區 1358127
## 12 萬華區 1284336
## # A tibble: 12 x 2
## district avg_disposable_income
## <chr> <dbl>
## 1 大安區 368929.8
## 2 中正區 342180.8
## 3 信義區 328257.2
## 4 松山區 315839.4
## 5 士林區 284198.2
## 6 內湖區 281973.8
## 7 北投區 281149.6
## 8 中山區 264363.2
## 9 南港區 262260.2
## 10 萬華區 252392.6
## 11 大同區 249795.2
## 12 文山區 247346.2
shiny 為上圖增加一個 checkbox 讓使用者選擇行政區library(shiny)
ui <- fluidPage(
titlePanel("行政區家戶所得變動趨勢"),
sidebarPanel(
checkboxGroupInput("districts", "Choose districts:",
choiceNames = unique(disposable_income$district),
choiceValues = unique(disposable_income$district),
selected = list("大同區")
)
),
mainPanel(
plotlyOutput("trendPlot")
)
)
server <- function(input, output) {
filtered_df <- reactive(
disposable_income %>%
filter(district %in% input$districts)
)
a <- list(
showticklabels = TRUE,
dtick = 1,
title = ""
)
output$trendPlot <- renderPlotly({
filtered_df() %>%
plot_ly(x = ~western_year, y = ~disposable_income, type = 'scatter', mode = 'lines', color = ~district) %>%
layout(xaxis = a)
})
}
shinyApp(ui, server)## # A tibble: 12 x 2
## district avg_price_per
## <chr> <dbl>
## 1 大安區 82.16021
## 2 信義區 69.03309
## 3 中正區 66.33535
## 4 松山區 65.89661
## 5 中山區 52.17915
## 6 士林區 47.86554
## 7 大同區 47.42488
## 8 南港區 47.31355
## 9 內湖區 44.75836
## 10 文山區 39.87396
## 11 萬華區 38.08835
## 12 北投區 37.64281
hh)ggplotly() 將上圖轉換為具有 plotly 效果的氣泡圖